﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using Microsoft.ApplicationBlocks.Data;
using FunkeLab;

namespace AnyOffice.general.ipanel
{
    public partial class menu_outlook_menu : BasePage
    {        

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack && (Request.QueryString["menu_id"] != null))
            {
                string str = Request.QueryString["menu_id"].ToString();
                UserCache cache = new UserCache();
                string funcIdStr = cache.FuncIdStr;
                string commandText = "SELECT * FROM [dbo].[Sys_Menu] WHERE [MenuId] = " + Request.QueryString["menu_id"].ToString();
                DataTable table = SqlHelper.ExecuteDataset(ConfigManager.ConnectionString, CommandType.Text , commandText).Tables[0];
                if (table.Rows.Count > 0)
                {
                    this.litMenuName.Text = table.Rows[0]["MenuName"].ToString();
                    this.litImage.Text = table.Rows[0]["Image"].ToString();
                }
                string str4 = "SELECT * FROM [dbo].[Sys_Function] WHERE CHARINDEX(','+ CAST([FuncId] as nvarchar(20)) + ',','," + funcIdStr + ",')>0 and len(MenuId)=4 and left(MenuId,2)='" + str + "' ORDER BY MenuId ASC";
                DataTable table2 = SqlHelper.ExecuteDataset(ConfigManager.ConnectionString, CommandType.Text, str4).Tables[0];
                if (table2.Rows.Count > 0)
                {
                    for (int i = 0; i < table2.Rows.Count; i++)
                    {
                        MyTreeViewItem item = new MyTreeViewItem();
                        item.Text = table2.Rows[i]["FuncName"].ToString();
                        item.Image = "/images/menu/" + table2.Rows[i]["FuncImg"].ToString() + ".gif";
                        if (table2.Rows[i]["FuncCode"].ToString().IndexOf("@") < 0)
                        {
                            if (table2.Rows[i]["FuncCode"].ToString().StartsWith("http://") || table2.Rows[i]["FuncCode"].ToString().StartsWith("file://"))
                            {
                                item.Link = table2.Rows[i]["FuncCode"].ToString();
                            }
                            else
                            {
                                item.Link = "../" + table2.Rows[i]["FuncCode"].ToString() + "/index.aspx";
                            }
                            item.TargetFrame = "main";
                        }
                        string str5 = "SELECT * FROM [dbo].[Sys_Function] WHERE (CHARINDEX(','+ CAST(FuncId as nvarchar(20)) + ',','," + funcIdStr + ",')>0) AND (len(MenuID)=6) AND (left(MenuID,4) ='" + table2.Rows[i]["MenuID"].ToString() + "') ORDER BY MenuId ASC";
                        DataTable table3 = SqlHelper.ExecuteDataset(ConfigManager.ConnectionString, CommandType.Text, str5).Tables[0];
                        if (table3.Rows.Count > 0)
                        {
                            for (int j = 0; j < table3.Rows.Count; j++)
                            {
                                MyTreeViewItem item2 = new MyTreeViewItem();
                                item2.Text = table3.Rows[j]["FuncName"].ToString();
                                item2.Image = "/images/menu/" + table3.Rows[j]["FuncImg"] + ".gif";
                                if (table3.Rows[j]["FuncCode"].ToString().StartsWith("http://") || table3.Rows[j]["FuncCode"].ToString().StartsWith("file://"))
                                {
                                    item2.Link = table3.Rows[j]["FuncCode"].ToString();
                                }
                                else
                                {
                                    item2.Link = "../" + table3.Rows[j]["FuncCode"].ToString() + "/index.aspx";
                                }
                                item2.TargetFrame = "main";
                                item.Items.Add(item2);
                            }
                        }
                        this.MyTreeView1.Items.Add(item);
                    }
                }
            }
        } 

    }
}
